@page "/TestSimple"

@using ZLJ.Application.Share.TestSimple

@attribute [ReuseTabsPage(Title = "普通数据测试")]
@attribute [Authorize(TestSimpleApplicationShareConsts.PermissionNameGet)]

@inherits ListBaseComponent<TestSimpleDto, long, PagedAndSortedResultRequest<TestSimpleCondition>>

<Flex Gap="small" Vertical Justify="space-between">
    @* 顶部工具栏 *@
    <Flex Justify="space-between">
        @* 左侧 *@
        <Flex Gap="small">
            @if (createIsGranted)
            {
                <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Plus" OnClick="BtnCreateClick" Disabled="IsBusy">新增</Button>
            }
            @if (deleteIsGranted)
            {
                <Popconfirm Title="确定删除已选择的项吗?" OnConfirm="BtnDeleteClick">
                    <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Clear" Danger Disabled="ShouldDisableDelete" Loading="isDeleting">删除</Button>
                </Popconfirm>
            }
        </Flex>
        @* 右侧 *@
        <Flex Gap="small">
            <AntDesign.InputNumber @bind-Value="GetAllInput.Filter.AgeMin" PlaceHolder="最小年龄"  Width="150"/>
            <AntDesign.InputNumber @bind-Value="GetAllInput.Filter.AgeMax" PlaceHolder="最大年龄"  Width="150"/>
            <RangePicker TValue="DateTime?[]" @bind-Value="BirthdayRange" Placeholder=@(new string[] { "开始出生日期", "结束出生日期" }) Width="150"/>
            <AntDesign.InputNumber @bind-Value="GetAllInput.Filter.F2Min" PlaceHolder="最小测试3" Precision="3" Width="150"/>
            <AntDesign.InputNumber @bind-Value="GetAllInput.Filter.F2Max" PlaceHolder="最大测试3" Precision="3" Width="150"/>
            <Input @bind-Value="GetAllInput.Filter.Status" PlaceHolder="状态" Width="150"/>
            <Input @bind-Value="GetAllInput.Filter.F3" PlaceHolder="测试4" Width="150"/>
            <div style="width:14.5rem;">
                <Search Placeholder="名称/字符串字段1等关键字..." @bind-Value="Keywords" OnChange="BtnSearchClick" AllowClear="true" Disabled="IsBusy" />
            </div>
            <Tooltip Title="清空条件">
                <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Clear" OnClick="BtnClearFilterClick" Disabled="IsBusy"></Button>
            </Tooltip>
            <Tooltip Title="刷新">
                <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Reload" OnClick="BtnRefreshClick" Disabled="IsBusy"></Button>
            </Tooltip>
        </Flex>

    </Flex>

    @* 表格 *@
    <Table @ref="table"
           TItem="TestSimpleDto"
           Total="TotalCount"
           @bind-SelectedRows="SelectedItems"
           OnChange="OnQuery"
           DataSource="Items"
           PageIndex="PageIndex"
           PageSize="PageSize"
           Loading="IsLoading"
           RowClassName="@(r=>r.RowIndex%2==0?"even":"odd")"
           RemoteDataSource="true"
           RowKey="x=>x.Id"
           OnRow="OnRow"
           Size="TableSize.Small"
           Bordered="true"
           ScrollY="71.5vh"
           ScrollX="1000px">

        <Selection Key="@context.Id.ToString()" Width="50" Fixed="left" />
        <Column TData=TestSimpleDto Title="行号" Width="60" Fixed="left">
            @(PageSize * (PageIndex - 1) + Items.IndexOf(context) + 1)
        </Column>

        <PropertyColumn Property="c=>c.Name" Sortable="true" ShowSorterTooltip="false" Width="150"  Align="@ColumnAlign.Center"/>        
        <PropertyColumn Property="c=>c.Age" Sortable="true" ShowSorterTooltip="false" Width="150"  Align="@ColumnAlign.Center"/>        
        <PropertyColumn Property="c=>c.Birthday" Sortable="true" ShowSorterTooltip="false" Width="150"  Align="@ColumnAlign.Center"/>        
        <PropertyColumn Property="c=>c.StringField1"  ShowSorterTooltip="false" Width="150"  Align="@ColumnAlign.Center"/>        
        <PropertyColumn Property="c=>c.Status" Sortable="true" ShowSorterTooltip="false" Width="150"  Align="@ColumnAlign.Center"/>        
        <PropertyColumn Property="c=>c.F2" Sortable="true" ShowSorterTooltip="false" Width="150"  Align="@ColumnAlign.Center"/>        
        <PropertyColumn Property="c=>c.F3" ShowSorterTooltip="false"   Width="5rem"  Align="@ColumnAlign.Center">
            <Switch @bind-Value="@context.F3" Size="@InputSize.Small" Disabled="true"></Switch>
        </PropertyColumn>
        <ActionColumn Title="操作" Width="160" Fixed="right">
            <ButtonGroup Size="@ButtonSize.Small">
                <Button Type="@ButtonType.Primary" OnClick="x=>BtnItemDetailClick(context)">详情</Button><br />
                @if (updateIsGranted)
                {
                    <Button OnClick="x=>BtnItemEditClick(context)">修改</Button>
                }
                @if (deleteIsGranted)
                {
                    <Popconfirm Title="确定删除此项吗?"
                                OnConfirm="()=>BtnDeleteItemClick(context)">
                        <Button Danger="true">删除</Button>
                    </Popconfirm>
                }
            </ButtonGroup>
        </ActionColumn>
    </Table>
</Flex>

@*新增弹窗*@
@{
    RenderFragment renderFragment = @<Template>
        <SectionOutlet SectionName=@($"{this.GetHashCode()}-create-btns") />
        <Button OnClick="CloseCreateDialog">关闭</Button>
    </Template>;
}
<Modal DestroyOnClose="true" 
       Footer="renderFragment" 
       @bind-Visible="isCreateDialogVisible" 
       Draggable="true"
       Class="frm-dal" 
       AfterClose="AfterCloseDialog">
    <TitleTemplate>
        <Icon Type="plus" Theme="outline" />新增@(FuncName)
    </TitleTemplate>
    <ChildContent>
        <SectionOutlet SectionName=@($"{this.GetHashCode()}-create-body") />
        <Create OnAddEnd="OnAddEnd" Master=@(this.GetHashCode()) />
    </ChildContent>
</Modal>

@*修改和详情弹窗*@
@{
    RenderFragment renderFragment1 = @<Template>
        <SectionOutlet SectionName=@($"{this.GetHashCode()}-detail-update-btns") />
        <Button OnClick="CloseUpdateOrDetail">关闭</Button>
    </Template>;
}
<Modal DestroyOnClose
       @bind-Visible="isShowDetailUpdate"
       Draggable="true"
       Title="详情"
       Width="@("50vw")"
       Class="frm-dal"
       Maximizable="false"
       AfterClose="AfterCloseDialog"
       Footer="renderFragment1"
       DefaultMaximized="false"
       MaxBodyHeight="86vh">
    <ChildContent>
        <SectionOutlet SectionName=@($"{this.GetHashCode()}-detail-update-body") />
        <DetailUpdate Id="detailUpdateId" IsEdit="isEdit" OnDeleted="DetailDeleted" OnUpdated="DetailUpdated" Master="GetHashCode()" />
    </ChildContent>
</Modal>